const db=wx.cloud.database();
Page({

  /**
   * 页面的初始数据
   */
  data: {
      taskid:0,
      task:[],
      sms:'',
      userid:'',
      connection:'',
      url:'',
  },
  userxq(e){
    wx.setStorageSync('userxq', e.currentTarget.id)
    wx.navigateTo({
      url: '../userxq/userxq',
    })
  },
  onChange(event) {
    // event.detail 为当前输入的值
    this.setData({
      sms:event.detail
    })
  },
  fasong(){
    let that=this;
    wx.cloud.callFunction({
      name:"openid"
    }).then(res=>{
      this.setData({
        userid:res.result.openid,
      })
      db.collection("user").where({
        _openid:this.data.userid
      }).get().then(a=>{
        that.setData({
          url:a.data[0].url
        })
        that.setData({
          connection:this.data.connection.concat({id:that.data.userid,value:that.data.sms,url:that.data.url})
        })
        db.collection("task").doc(this.data.taskid).update({
          data:{
            connection:this.data.connection
          }
        }).then(b=>{
          that.setData({sms:''})
        })
      })

      
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    let that=this
    this.setData({
      taskid:wx.getStorageSync('taskms')
    })
    db.collection("task").doc(this.data.taskid).get().then(res=>{
      this.setData({
        task:res.data,
        connection:res.data.connection
      })
      
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    wx.showLoading({
      title: '加载中',
    })
    let that=this
    this.setData({
      taskid:wx.getStorageSync('taskms')
    })
    db.collection("task").doc(this.data.taskid).get().then(res=>{
      this.setData({
        task:res.data,
        connection:res.data.connection
      })
      
    })
    wx.hideLoading({
      success: (res) => {},
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    let that=this
    this.setData({
      taskid:wx.getStorageSync('taskms')
    })
    db.collection("task").doc(this.data.taskid).get().then(res=>{
      this.setData({
        task:res.data,
        connection:res.data.connection
      })
      
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})